<?php
if (!defined('ROOT_PATH')) die('No direct access.');
if ((isset($param[2])) && (isset($param[3])) && ($param[1]=='a')){
	view_artikel($param[2]);
}else if (isset($param[2])){
	if (isset($_SESSION['logged'])){
		switch ($param[1]){
			case 'buat' :
				if (isset($_POST['submit'])){
					$judul = $_POST['judul'];
					$isi = htmlentities($_POST['isi']);
					$tag = $_POST['tag'];
					$idpub = $_SESSION['logged']['index'];
					$idrev = $_POST['idrev'];
					$ret = addArtikel($judul,$isi,$tag,$idpub,$idrev,$param[3]);
					$artikel = getArtikel($ret);
					if ($ret){
						//tambahpoin(id,100);
						header('Location: ' .BLOG_URL.'a/'.$artikel['idArtikel'].'/'.$artikel['slug-judul']);	//redirect ke halaman artikelnya
					}else
						header('Location: ' . $_SERVER['HTTP_REFERER']);	//redirect ke halaman editing
				}else
					view_buat($param[2],$param[3]);
				break;
			case 'edit' :
				if (isset($_POST['submit'])){
					$index = $_POST['index'];
					$judul = $_POST['judul'];
					$isi = htmlentities($_POST['isi']);
					$tag = $_POST['tag'];
					//print_r($_POST);
					$ret = editArtikel($judul,$isi,$tag,$index);
					$artikel = getArtikel($index);
					if ($ret!=0) header('Location: ' .BLOG_URL.'a/'.$artikel['idArtikel'].'/'.$artikel['slug-judul']);	//redirect ke halaman artikelnya
						else
					header('Location: ' . $_SERVER['HTTP_REFERER']);	//redirect ke halaman editing
				}else
					edit_buat($param[2],$param[3],$param[4]);
					//echo $param[3];
				break;
			default:
				view_404();
				break;
		}
	}else
		view_404();
}else
	view_blog($param);
